﻿using Newtonsoft.Json;
using Restaurant.Common;
using Restaurant.Model;
using Restaurant.Model.ExModel;
using Restaurant.Site;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Description;

namespace Restaurant.API.Client.Controllers
{
    /// <summary>
    /// 菜品相关
    /// </summary>
    public class FoodController : ApiController
    {

        /// <summary>
        /// 获取 所有菜品分类关联菜品
        /// </summary>
        /// <param name="subId">公司ID</param>
        /// <returns></returns>
        [ResponseType(typeof(OperationResult))]
        [HttpGet]
        public async Task<HttpResponseMessage> GetAllAsync(Guid subId)
        {
            var i = new FoodSite();

            var fModel = await i.GetAllFoodTypeAndFoodAsync(subId);
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content = new StringContent(JsonConvert.SerializeObject(fModel), System.Text.Encoding.UTF8, "application/json"),

            };

            return httpResponseMessage;

        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<HttpResponseMessage> AddAsync(FoodType_Food_Ex model)
        {
            var i = new FoodSite();

            var fModel = await i.AddModeExAsync(model);
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content = new StringContent(JsonConvert.SerializeObject(fModel), System.Text.Encoding.UTF8, "application/json"),

            };

            return httpResponseMessage;

        }


        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [ResponseType(typeof(OperationResult))]
        [HttpDelete]
        public async Task<HttpResponseMessage> DeleteAsync(long id)
        {
            var i = new FoodSite();

            var fModel = await i.DeleteAsync(id);
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content = new StringContent(JsonConvert.SerializeObject(fModel), System.Text.Encoding.UTF8, "application/json"),

            };

            return httpResponseMessage;
        }


    }
}
